import api from '../../api';
import { message } from 'antd';

export default {
  namespace: 'cashManagementReportM',
  state: {
    securityBondTypeList: [],
    investmentRangeData: [
      {
        title: '',
      },
    ],
  },

  effects: {
    // 获取前一交易日
    *getTradingDate({ payload, callback }, { call, put }) {
      const res = yield call(api.getTradingDate, payload);
      if (res && res.message == 'success') {
        callback(res.data);
      } else {
        message.error(res?.message);
      }
    },
    // 查询个券偏离度接口
    *getDeviationControl({ payload, callback }, { call, put }) {
      const res = yield call(api.cashManagementReport.getDeviationControl, payload);
      callback(res);
    },
    // 查询租户是否有个券偏离度条目
    *getConfigured({ payload, callback }, { call, put }) {
      const res = yield call(api.cashManagementReport.getConfigured, payload);
      if (res && res.code == '0') {
        callback(res.data);
      } else {
        callback();
        message.error(res?.msg || '查询租户是否有个券偏离度条目失败!');
      }
    },
    // 保存编辑说明
    *saveDescription({ payload, callback }, { call, put }) {
      const res = yield call(api.cashManagementReport.saveDescription, payload);
      if (res && res.code == '0') {
        message.success('保存成功 !');
        callback();
      } else {
        message.error(res?.msg || '保存说明失败!');
      }
    },

    // 查看说明
    *quereyEditInfo({ payload, callback }, { call, put }) {
      const res = yield call(api.cashManagementReport.quereyEditInfo, payload);
      if (res && res.code == 0) {
        res.data?.forEach((item, index) => {
          item.key = index;
        });
        callback(res.data);
      } else {
        callback();
        message.error(res?.msg || '查看说明列表失败!');
      }
    },

    // 查询现金报告唯一接口
    *queryReport({ payload, callback }, { call, put }) {
      const res = yield call(api.cashManagementReport.queryReport, payload);
      callback(res);
    },
    // 更新未读消息
    *updateUnreadDate({ payload }, { call, put }) {
      const res = yield call(api.updateUnreadDate, payload);
      if (!res || res.code != 0) {
        message.error(`更新未读消息失败，失败原因：${res?.msg}`);
      }
    },
  },
  reducers: {
    save(state, { payload }) {
      return {
        ...state,
        ...payload,
      };
    },
  },
};
